import { req_downloadFile } from '../api/req_fun'


export function req_DownLoad_file(item) {
    console.log(item);
    const promisetest = req_downloadFile({
        courseId: item.courseId,
        attachmentId: item.id
    }).then(({ data: res }) => {
        const blob = new Blob([res])
        const fileName = item.attachmentName
        const extentNamr = item.attachmentUrl.substring(item.attachmentUrl.lastIndexOf('.'))
        const fullName = fileName + extentNamr
        const link = document.createElement('a')
        link.download = fullName
        link.target = '_blank';
        link.style.display = 'none'
        link.href = URL.createObjectURL(blob);
        document.body.appendChild(link)
        link.click()
        URL.revokeObjectURL(link.href);
        document.body.removeChild(link)
    }).catch((err) => {
        console.log('err', err);
    })
}   